<template>
  <div class="" id="GerrirReview">
    <el-row>
        <el-col :xs="24" :sm="24" :lg="24" class="primary">代码评审</el-col>
    </el-row>
    <el-row>
        <el-col :xs="24" :sm="24" :lg="24" class="border"></el-col>
    </el-row>
    <el-row>
        <el-col :xs="24" :sm="24" :lg="24">
          <datepickersummary></datepickersummary>
        </el-col>
      </el-row>
    <template v-if="!filters.radio">
        <el-row :gutter="30" key="1">
            <el-col :xs="24" :sm="24" :lg="6">
                <LabelGrid :label_info="label_info.patch" :label_data="getFix(label_data.number__count)"></LabelGrid>
            </el-col>
            <el-col :xs="24" :sm="24" :lg="6">
                <LabelGrid :label_info="label_info.insert" :label_data="getFix(label_data.lines_insert__sum)"></LabelGrid>
            </el-col>
            <el-col :xs="24" :sm="24" :lg="6">
                <LabelGrid :label_info="label_info.delete" :label_data="getFix(label_data.lines_delete__sum)"></LabelGrid>
            </el-col>
            <el-col :xs="24" :sm="24" :lg="6">
                <LabelGrid :label_info="label_info.effective_code" :label_data="getFix(label_data.effective_code)"></LabelGrid>
            </el-col>
            <el-col :xs="24" :sm="24" :lg="6">
                <LabelGrid :label_info="label_info.inline_c" :label_data="getFix(label_data.inline_comments__sum)"></LabelGrid>
            </el-col>
            <el-col :xs="24" :sm="24" :lg="6">
                <LabelGrid
                    :label_info="label_info.patch_without_inline_c"
                    :label_data="getFix(label_data.no_comment_patch)"
                    :filters="filters">
                </LabelGrid>
            </el-col>
            <el-col :xs="24" :sm="24" :lg="6">
                <LabelGrid :label_info="label_info.defect_concentration" :label_data="getFix(label_data.defect_density)"></LabelGrid>
            </el-col>
            <el-col :xs="24" :sm="24" :lg="6">
                <LabelGrid :label_info="label_info.defect_effective_rate" :label_data="getFix(label_data.effective_ratio)"></LabelGrid>
            </el-col>
            <el-col :xs="24" :sm="24" :lg="6">
                <LabelGrid :label_info="label_info.incorrect_inbound_code" :label_data="getFix(label_data.incorrect_inbound_code)"></LabelGrid>
            </el-col>
            <el-col :xs="24" :sm="24" :lg="6">
                <LabelGrid :label_info="label_info.invalid_association_set" :label_data="getFix(label_data.invalid_association_set)"></LabelGrid>
            </el-col>
        </el-row>

        <div class="problem-wrapper" style="margin-bottom: 20px;">
            <el-row :gutter="30" class="dangerous">
                <el-col :xs="24" :sm="24" :lg="12">
                    <el-card class="box-card m-b" shadow="never">
                        <div slot="header" class="clearfix" style="vertical-align:middle">
                            <div style="float: left; padding: 10px 0">发现问题数排名</div>
                        </div>
                        <div>
                            <VTable
                                :rank="true"
                                :height="'540px'"
                                :loading="ploadingProj"
                                :tablesize="problemSizeProj"
                                :tablecurrent="problemCurrentProj"
                                :tabletotal="problemTotalProj"
                                :table-data="problemDataProj"
                                :table-label="problemLabelProj"
                                @tableSizeChange="problemSizeChangeProj"
                                @tableCurrentImportDeptChange="problemCurrentImportDeptChangeProj"
                            >
                            </VTable>
                        </div>
                    </el-card>
                </el-col>

                <el-col :xs="24" :sm="24" :lg="12">
                    <el-card class="box-card m-b" shadow="never">
                        <div slot="header" class="clearfix" style="vertical-align:middle">
                            <div style="float: left; padding: 10px 0">评审密度排名</div>
                        </div>
                        <div>
                            <VTable
                                :rank="true"
                                :height="'540px'"
                                :loading="defectLoadingProj"
                                :tablesize="defectSizeProj"
                                :tablecurrent="defectCurrentProj"
                                :tabletotal="defectTotalProj"
                                :table-data="defectDensityProj"
                                :table-label="defectDensityLabelProj"
                                @tableSizeChange="defectSizeChangeProj"
                                @tableCurrentImportDeptChange="defectCurrentImportDeptChangeProj"
                            >
                            </VTable>
                        </div>
                    </el-card>
                </el-col>
            </el-row>
        </div>

        <chartgerrit></chartgerrit>

        <!-- 评审数据表 -->
        <el-row class="bgColor marT" style="margin-bottom: 20px;">
            <el-col :xs="24" :sm="24" :lg="24">
                <div class="ibox-title pad">评审数据列表</div>

                <div class="table mar">
                    <VTable
                        :rank="false"
                        :loading="gerritLoadingProj"
                        :tablesize="gerritSizeProj"
                        :tablecurrent="gerritCurrentProj"
                        :tabletotal="gerritTotalProj"
                        :table-data="gerritTableProj"
                        :table-label="gerritLabelProj"
                        :layout="'total, prev, pager, next, jumper'"
                        @tableSizeChange="gerritSizeChangeProj"
                        @tableCurrentImportDeptChange="gerritCurrentImportDeptChangeProj"
                    ></VTable>
                </div>
            </el-col>
        </el-row>

        <tablegerritdaily></tablegerritdaily>

        <tablegerritcomponent></tablegerritcomponent>
    </template>

    <template v-else>
        <el-row :gutter="30" key="2">
            <el-col :xs="24" :sm="24" :lg="6">
                <LabelGrid :label_info="deptlableinfo.patchtotal" :label_data="getFix(deptlable.number__count)"></LabelGrid>
            </el-col>

            <el-col :xs="24" :sm="24" :lg="6">
                <LabelGrid :label_info="deptlableinfo.inline" :label_data="getFix(deptlable.inline_comments__sum)"></LabelGrid>
            </el-col>

            <el-col :xs="24" :sm="24" :lg="6">
                <LabelGrid
                :label_info="deptlableinfo.defect_concentration"
                :label_data="getNum(deptlable.defect_density)"
                :label_import="'big'"
                :label_avg="standardKPI.code_defect_density_avg_project"
                :label_now="deptlable.defect_density"
                :label_good="kpi.code_defect_density_avg_project"
                :label_precent="'num'"
                :nessary="true">
                </LabelGrid>
            </el-col>

            <el-col :xs="24" :sm="24" :lg="6">
                <LabelGrid
                :label_info="deptlableinfo.defect_effective_rate"
                :label_data="getNum(deptlable.effective_ratio)"
                :label_import="'big'"
                :label_avg="standardKPI.code_effective_ratio_avg_project"
                :label_now="deptlable.effective_ratio"
                :label_good="kpi.code_effective_ratio_avg_project"
                :label_precent="'num'"
                :nessary="true">
                </LabelGrid>
            </el-col>
        </el-row>

        <div class="problem-wrapper" style="margin-bottom: 20px;">
            <el-row :gutter="30" class="dangerous">
                <el-col :xs="24" :sm="24" :lg="12">
                    <el-card class="box-card m-b" shadow="never">
                        <div slot="header" class="clearfix" style="vertical-align:middle">
                        <div style="float: left; padding: 10px 0">按个人</div>
                        <el-radio-group v-model="problemSelected" style="float: right; padding: 3px 0" size="mini">
                            <el-radio-button label="发现问题数排名"></el-radio-button>
                            <el-radio-button label="评审密度排名"></el-radio-button>
                        </el-radio-group>
                        </div>
                        <div v-if="problemSelected == '发现问题数排名'">
                            <VTable
                                :rank="true"
                                :loading="ploading"
                                :tablesize="problemSize"
                                :tablecurrent="problemCurrent"
                                :tabletotal="problemTotal"
                                :table-data="problemData"
                                :table-label="problemLabel"
                                @tableSizeChange="problemSizeChange"
                                @tableCurrentImportDeptChange="problemCurrentImportDeptChange"
                            >
                            </VTable>
                        </div>
                        <div v-else>
                            <VTable
                                :rank="true"
                                :loading="defectLoading"
                                :tablesize="defectSize"
                                :tablecurrent="defectCurrent"
                                :tabletotal="defectTotal"
                                :table-data="defectDensity"
                                :table-label="defectDensityLabel"
                                @tableSizeChange="defectSizeChange"
                                @tableCurrentImportDeptChange="defectCurrentImportDeptChange"
                            >
                            </VTable>
                        </div>
                    </el-card>
                </el-col>

                <el-col :xs="24" :sm="24" :lg="12">
                    <el-card class="box-card m-b" shadow="never">
                        <div slot="header" class="clearfix" style="vertical-align:middle">
                        <div style="float: left; padding: 10px 0">按项目</div>
                        <el-radio-group v-model="importedSelected2" style="float: right; padding: 3px 0" size="mini">
                            <el-radio-button label="代码评审注释"></el-radio-button>
                            <el-radio-button label="评审缺陷密度(平均)"></el-radio-button>
                            <el-radio-button label="评审有效比率"></el-radio-button>
                        </el-radio-group>
                        </div>
                        <div v-if="importedSelected2 === '代码评审注释'">
                            <el-table
                                :data="deptrank2.slice((currentPage2-1)*pageSize2,currentPage2*pageSize2)"
                                style="width: 100%"
                                v-loading="loading2"
                                >
                                <el-table-column width="100" align="center" label="排名">
                                <template slot-scope="scope">
                                    <el-tag v-if="scope.$index=== 0 && currentPage2 === 1" type="danger" size="medium" >
                                    TOP{{ scope.$index + 1 }}
                                    </el-tag>
                                    <el-tag v-else-if="scope.$index=== 1 && currentPage2 === 1" type="warning" size="medium" >
                                    TOP{{ scope.$index + 1 }}
                                    </el-tag>
                                    <el-tag v-else-if="scope.$index=== 2 && currentPage2 === 1" type="primary" size="medium" >
                                    TOP{{ scope.$index + 1 }}
                                    </el-tag>
                                    <span v-else> {{scope.$index + 1 + pageSize2*(currentPage2 - 1)}} </span>
                                </template>
                                </el-table-column>
                                <el-table-column
                                prop="project_name"
                                align="center"
                                label="项目">
                                </el-table-column>
                                <el-table-column
                                prop="inline_comments"
                                label="代码注释数"
                                align="center"
                                >
                                </el-table-column>
                            </el-table>
                            <el-pagination class="marT"
                                :page-size="pageSize2"
                                background
                                @size-change="handleSizeChange2"
                                @current-change="handleCurrentImportDeptChange2"
                                :current-page="currentPage2"
                                layout="prev, pager, next"
                                style="text-align: center"
                                :total="totalDeptData2">
                            </el-pagination>
                        </div>
                        <div v-else-if="importedSelected2 === '评审缺陷密度(平均)'"> <!--  v-if="importedSelected === '事业部'" -->
                            <el-table
                                :data="deptrank3.slice((currentPage3-1)*pageSize3,currentPage3*pageSize3)"
                                style="width: 100%"
                                v-loading="loading3"
                                >
                                <el-table-column width="100" align="center" label="排名">
                                <template slot-scope="scope">
                                    <el-tag v-if="scope.$index=== 0 && currentPage3 === 1" type="danger" size="medium" >
                                    TOP{{ scope.$index + 1 }}
                                    </el-tag>
                                    <el-tag v-else-if="scope.$index=== 1 && currentPage3 === 1" type="warning" size="medium" >
                                    TOP{{ scope.$index + 1 }}
                                    </el-tag>
                                    <el-tag v-else-if="scope.$index=== 2 && currentPage3 === 1" type="primary" size="medium" >
                                    TOP{{ scope.$index + 1 }}
                                    </el-tag>
                                    <span v-else> {{scope.$index + 1 + pageSize3*(currentPage3 - 1)}} </span>
                                </template>
                                </el-table-column>
                                <el-table-column
                                prop="project_name"
                                align="center"
                                label="项目">
                                </el-table-column>
                                <el-table-column
                                prop="defect_density"
                                label="评审缺陷密度"
                                align="center"
                                >
                                </el-table-column>
                            </el-table>
                            <el-pagination class="marT"
                                :page-size="pageSize3"
                                background
                                @size-change="handleSizeChange3"
                                @current-change="handleCurrentImportDeptChange3"
                                :current-page="currentPage3"
                                layout="prev, pager, next"
                                style="text-align: center"
                                :total="totalDeptData3">
                            </el-pagination>
                        </div>
                        <div v-else>
                            <el-table
                                :data="deptrank4.slice((currentPage4-1)*pageSize4,currentPage4*pageSize4)"
                                style="width: 100%"
                                >
                                <el-table-column width="100" align="center" label="排名">
                                <template slot-scope="scope">
                                    <el-tag v-if="scope.$index=== 0 && currentPage4 === 1" type="danger" size="medium" >
                                    TOP{{ scope.$index + 1 }}
                                    </el-tag>
                                    <el-tag v-else-if="scope.$index=== 1 && currentPage4 === 1" type="warning" size="medium" >
                                    TOP{{ scope.$index + 1 }}
                                    </el-tag>
                                    <el-tag v-else-if="scope.$index=== 2 && currentPage4 === 1" type="primary" size="medium" >
                                    TOP{{ scope.$index + 1 }}
                                    </el-tag>
                                    <span v-else> {{scope.$index + 1 + pageSize4*(currentPage4 - 1)}} </span>
                                </template>
                                </el-table-column>
                                <el-table-column
                                prop="project_name"
                                align="center"
                                label="项目">
                                </el-table-column>
                                <el-table-column
                                prop="effective_ratio"
                                label="评审有效比率"
                                align="center"
                                >
                                </el-table-column>
                            </el-table>
                            <el-pagination class="marT"
                                :page-size="pageSize4"
                                background
                                @size-change="handleSizeChange4"
                                @current-change="handleCurrentImportDeptChange4"
                                :current-page="currentPage4"
                                layout="prev, pager, next"
                                style="text-align: center"
                                :total="totalDeptData4">
                            </el-pagination>
                        </div>
                    </el-card>
                </el-col>
            </el-row>
        </div>

        <div class="patch-container marT">
            <el-row>
                <el-col :xs="24" :sm="24" :lg="24">
                    <el-tabs class="bgColor" type="border-card" v-model="activePrecent">
                        <!-- <el-tab-pane name="0" label="代码提交趋势">
                            <ve-line
                            :data="patchData"
                            :settings="lineChartSettings"
                            ref="vline0"
                            :data-empty="dataEmpty"></ve-line>
                        </el-tab-pane> -->
                        <el-tab-pane name="0" label="评审缺陷密度(平均)">
                            <ve-line
                            v-loading="loadingLine"
                            :data="patchData2"
                            :settings="lineChartSettings"
                            ref="vline0"
                            :data-empty="dataEmpty"></ve-line>
                        </el-tab-pane>
                        <el-tab-pane name="1" label="评审有效比例">
                            <ve-line
                            :data="patchData3"
                            :settings="lineChartSettings"
                            ref="vline1"
                            :data-empty="dataEmpty"></ve-line>
                        </el-tab-pane>
                    </el-tabs>

                </el-col>
            </el-row>
        </div>

        <!-- 评审数据表 -->
        <el-row class="bgColor marT">
            <el-col :xs="24" :sm="24" :lg="24">
                <div class="ibox-title pad">评审数据列表</div>

                <div class="table mar">
                    <VTable
                        :rank="false"
                        :loading="gerritLoading"
                        :tablesize="gerritSize"
                        :tablecurrent="gerritCurrent"
                        :tabletotal="gerritTotal"
                        :table-data="gerritTable"
                        :table-label="gerritLabel"
                        :layout="'total, prev, pager, next, jumper'"
                        @tableSizeChange="gerritSizeChange"
                        @tableCurrentImportDeptChange="gerritCurrentImportDeptChange"
                    ></VTable>
                </div>
            </el-col>
        </el-row>

        <!-- 项目列表 -->
        <el-row class="bgColor marT">
            <el-col :xs="24" :sm="24" :lg="24">
                <div class="ibox-title pad">项目列表</div>

                <div class="table mar">
                    <el-table v-loading="loading" :data="tableData" :header-cell-style="{background:'#eef1f6'}" style="width: 100%">
                        <el-table-column
                            align="center"
                            type="index"
                            label="编号"
                            width="60">
                            <template slot-scope="scope">
                                <span>{{ scope.$index + 1 + tablesize*(tablecurrent - 1) }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column
                            align="center"
                            prop="project_name"
                            label="项目名称"
                            width="200">
                        </el-table-column>
                        <el-table-column
                            align="center"
                            prop="number__count"
                            label="patch(个)"
                            width="150">
                        </el-table-column>
                        <el-table-column
                            align="center"
                            prop="lines_insert__sum"
                            label="代码新增(Kloc)"
                            width="130">
                        </el-table-column>
                        <el-table-column
                            align="center"
                            prop="lines_delete__sum"
                            label="代码删除(Kloc)"
                            width="150">
                        </el-table-column>
                        <el-table-column
                            align="center"
                            prop="inline_comments__sum"
                            label="代码评审注释(个)"
                            width="150">
                        </el-table-column>
                        <el-table-column
                            align="center"
                            prop="defect_review"
                            label="评审缺陷密度(个/Kloc)"
                            width="200">
                        </el-table-column>
                        <el-table-column
                            align="center"
                            prop="effective_radio"
                            label="评审有效比率"
                            width="130">
                        </el-table-column>
                        <!-- <el-table-column
                            align="center"
                            prop="no_comment_patch"
                            label="无效关联"
                            width="130">
                        </el-table-column> -->
                        <el-table-column
                            align="center"
                            prop="effective_code"
                            label="有效代码(Kloc)"
                            >
                        </el-table-column>
                    </el-table>

                    <el-pagination class="marT"
                        :page-size="tablesize"
                        background
                        @size-change="tableSizeChange"
                        @current-change="tableCurrentImportDeptChange"
                        :current-page="tablecurrent"
                        layout="total, prev, pager, next, jumper"
                        style="text-align: center"
                        :total="tabletotal">
                    </el-pagination>
                </div>
            </el-col>
        </el-row>
    </template>

  </div>
</template>

<script>
// import { getHeader } from '@/app.config.js';
// @ is an alias to /src
import LabelGrid from '@/components/qa/Label.vue'
import DatePickerSummary from '@/views/summary/DatePickerSummary'
import ElDatePickerSingle from '@/components/qa/ElDatePickerSingle.vue'
import TableGerritDaily from '@/components/qa/GerritReview/TableGerritDaily.vue'
import TableGerritComponent from '@/components/qa/GerritReview/TableGerritComponent.vue'
import ChartGerrit from '@/components/qa/GerritReview/ChartGerrit.vue'
import { getPMSLink, getHeader } from '@/app.config';
import { mapState, mapMutations } from 'vuex'
import { getKpi2 } from '@/api/kpi'
import VTable from '@/components/charts/table'

export default {
    name: 'GerrirReview',
    components: {
        eldatepickersingle: ElDatePickerSingle,
        tablegerritdaily: TableGerritDaily,
        tablegerritcomponent: TableGerritComponent,
        chartgerrit: ChartGerrit,
        LabelGrid,
        VTable,
        datepickersummary: DatePickerSummary
    },
    data () {
        return {
            kpi: {},
            nessary: true,
            loading: true,
            loading2: true,
            loading3: true,
            loadingLine: true,
            project_id: '',
            project_name:'',
            activePrecent: 0,
            problemSelected: '发现问题数排名',
            // importedSelected: '代码提交数排名(个人)',
            importedSelected2: '代码评审注释',
            deptlableinfo: {
                patchtotal: {
                    label_hname: 'Patch提交',
                    label_sname: '总计',
                    label_unit: '(个)',
                    label_class: 'danger',
                },
                inline: {
                    label_hname: '代码评审注释',
                    label_sname: '总计',
                    label_unit: '(个)',
                    label_class: 'danger',
                },
                defect_concentration: {
                    label_hname: '评审缺陷密度',
                    // label_sname: '平均',
                    label_unit: '(个/Kloc)',
                    label_import: 'big',
                    label_class: 'success',
                    label_header: 'Avg',
                    label_title: '计算公式: 代码评审注释(个)/代码新增(千行)'
                },
                defect_effective_rate: {
                    label_hname: '评审有效比率',
                    label_header: 'Avg',
                    // label_sname: '总计',
                    label_unit: '(个)',
                    label_class: 'success',
                    label_title: '计算公式: 行内注释总数/patch总数'
                }
            },
            tableData: [],
            problemData: [],
            problemLabel: [
                {
                   label: '评审人员',
                   param: 'author_email',
                   align: 'center'
                },
                {
                   label: '发现问题数',
                   param: 'comments_count',
                   align: 'center'
                }
            ],
            problemDataProj: [],
            problemLabelProj: [
                {
                   label: '评审人员',
                   param: 'author_email',
                   align: 'center'
                },
                {
                   label: '发现问题数',
                   param: 'comments_count',
                   align: 'center'
                }
            ],
            gerritTable: [],
            gerritLabel: [
                {
                   label: '模块名称',
                   param: 'module',
                   align: 'center'
                },
                {
                   label: '问题数',
                   param: 'comments',
                   align: 'center'
                },
                {
                   label: '代码行数(Kloc)',
                   param: 'code_line',
                   align: 'center'
                },
                {
                   label: '评审缺陷密度(个/Kloc)',
                   param: 'bug_density',
                   align: 'center',
                   render: (row) => {
                       return Number(row.bug_density).toFixed(2)
                   }
                }
            ],
            gerritTotal: 0,
            gerritCurrent: 1,
            gerritSize: 10,
            gerritLoading: true,
            gerritTableProj: [],
            gerritLabelProj: [
                {
                   label: '模块名称',
                   param: 'module',
                   align: 'center'
                },
                {
                   label: '问题数',
                   param: 'comments',
                   align: 'center'
                },
                {
                   label: '代码行数(Kloc)',
                   param: 'code_line',
                   align: 'center'
                },
                {
                   label: '评审缺陷密度(个/Kloc)',
                   param: 'bug_density',
                   align: 'center',
                   render: (row) => {
                       return Number(row.bug_density).toFixed(2)
                   }
                }
            ],
            gerritTotalProj: 0,
            gerritCurrentProj: 1,
            gerritSizeProj: 10,
            gerritLoadingProj: true,
            problemTotal: 0,
            problemCurrent: 1,
            problemSize: 10,
            ploading: true,
            problemTotalProj: 0,
            problemCurrentProj: 1,
            problemSizeProj: 10,
            ploadingProj: true,
            defectDensity: [],
            defectDensityLabel: [
                {
                   label: '个人',
                   param: 'submitter',
                   align: 'center'
                },
                {
                   label: '问题数量',
                   param: 'comments',
                   align: 'center'
                },
                {
                   label: '代码行数(Kloc)',
                   param: 'code_line',
                   align: 'center'
                },
                {
                   label: '缺陷密度(个/Kloc)',
                   param: 'bug_density',
                   align: 'center'
                }
            ],
            defectTotal: 0,
            defectCurrent: 1,
            defectSize: 10,
            defectLoading: true,
            defectDensityProj: [],
            defectDensityLabelProj: [
                {
                   label: '个人',
                   param: 'submitter',
                   align: 'center'
                },
                {
                   label: '问题数量',
                   param: 'comments',
                   align: 'center'
                },
                {
                   label: '代码行数(Kloc)',
                   param: 'code_line',
                   align: 'center'
                },
                {
                   label: '缺陷密度(个/Kloc)',
                   param: 'bug_density',
                   align: 'center'
                }
            ],
            defectTotalProj: 0,
            defectCurrentProj: 1,
            defectSizeProj: 10,
            defectLoadingProj: true,
            patchData: {
                columns: ['update_time', 'number__count'],
                rows: []
            },
            patchData2: {
                columns: ['update_time', 'defect_density'],
                rows: []
            },
            patchData3: {
                columns: ['update_time', 'effective_radio'],
                rows: []
            },
            lineChartSettings: {
				labelMap: {
                    number__count: '代码提交总数',
                    defect_density: '评审缺陷密度(平均)',
                    effective_radio: '评审有效比例'
				}
            },
            dataEmpty: true,
            deptrank1: [],
            deptrank2: [],
            deptrank3: [],
            deptrank4: [],
            totalDeptData: 0,
            pageSize: 10,
            currentPage: 1,
            totalDeptData2: 0,
            pageSize2: 10,
            currentPage2: 1,
            totalDeptData3: 0,
            pageSize3: 10,
            currentPage3: 1,
            totalDeptData4: 0,
            pageSize4: 10,
            currentPage4: 1,
            tabletotal: 0,
            tablesize: 10,
            tablecurrent: 1,
            label_info: {
                patch: {
                    label_hname: 'Patch',
                    label_sname: '总计',
                    label_unit: '(个)',
                    label_class: 'success',
                },
                insert: {
                    label_hname: '代码新增',
                    label_sname: '总计',
                    label_unit: '(行)',
                    label_class: 'success',
                },
                delete: {
                    label_hname: '代码删除',
                    label_sname: '总计',
                    label_unit: '(行)',
                    label_class: 'danger',
                },
                inline_c: {
                    label_hname: '代码评审注释',
                    label_sname: '总计',
                    label_unit: '(个)',
                    label_class: 'success',
                },
                patch_without_inline_c: {
                    label_hname: '无行内注释Patch',
                    label_sname: '总计(新增代码大于100行)',
                    label_unit: '(个)',
                    label_class: 'danger',
                    url: 'gerrit-review-detail',
                    label_name: 'patch_without_inline_c',
                },
                defect_concentration: {
                    label_hname: '评审缺陷密度',
                    label_sname: '总计',
                    label_unit: '(个/Kloc)',
                    label_class: 'warning',
                    label_title: '计算公式: 代码评审注释(个)/代码新增(千行)'
                },
                defect_effective_rate: {
                    label_hname: '评审有效比率',
                    label_sname: '总计',
                    label_unit: '',
                    label_class: 'warning',
                    label_title: '计算公式: 行内注释总数/patch总数'
                },
                effective_code: {
                    label_hname: '有效代码',
                    label_sname: '总计',
                    label_unit: '(行)',
                    label_class: 'warning',
                    label_title: '计算公式: (代码新增-代码删除)*0.75'
                },
                incorrect_inbound_code: {
                    label_hname: '错误入库',
                    label_sname: '总计',
                    label_unit: '(个)',
                    label_class: 'danger'
                },
                invalid_association_set: {
                    label_hname: '无效关联',
                    label_sname: '总计',
                    label_unit: '(个)',
                    label_class: 'danger'
                }
            },
            label_data: {},
            deptlable: {}
        }
    },
    computed: {
        ...mapState({
            filters: state => state.filters,
            allDepartmentList: state => state.allDepartmentList,
            standardKPI: state => state.standardKPI
        })
    },
    watch: {
        filters: {
            handler: function() {
                this.getData()
            },
            deep: true,
        },
        activePrecent(v) {
            this.$nextTick(() => {
				this.$refs[`vline${v}`].echarts.resize()
			})
        },
        problemSelected(v) {
            if(v == '评审密度排名') {
                if(this.defectDensity.length) {
                    return
                } else {
                    let data = {}
                    this.defectLoading = true
                    if(this.filters.departList.length) {
                        data = {departmentIds: this.filters.departmentId}
                    } else {
                        data = {departmentIds: this.allDepartmentList.allDepartmentList}
                    }
                    this.$axios.post(`${process.env.VUE_APP_KANBAN_HOST}/api/qa/dept-owner-density-rank?time=${this.filters.time}`, data, {headers: getHeader()}).then(res => {
                        if(res.status == 200) {
                            if(res.data.code == 200) {
                                this.defectLoading = false
                                this.defectDensity = res.data.density_rank
                                this.defectTotal = this.defectDensity.length
                            }
                        }
                    })
                }
            }
        }
    },
    methods: {
        getLabelKpi(type) {
            getKpi2(type).then(res => {
                if (res.status == 200) {
                    if (res.data.code === 200) {
                        this.kpi = res.data.avg_kpi
                    } else {
                        this.nessary = false
                    }
				}
            })
        },
        getData: function() {
            let project = this.filters.projectId
            let departmentId = this.filters.departmentId
            let time = this.filters.time

            if(!this.filters.radio) {
                this.getCodeSummary(project, time, departmentId)
                this.getProjProblem()
                this.getProjdefect()
                this.getProjGerritTable()
            } else {
                this.getdeptCodeSummary()
                this.getLabelKpi('CodeReview')
                this.getDeptProblem()
                this.getDeptGerritTable()
                this.getdeptrank()
                this.getDeptRank2()
                this.getdaily()
                this.tablekpi()
            }
        },
        handleSizeChange(val) {
            //console.log(val)
            this.pageSize = val
        },
        handleCurrentImportDeptChange(page) {
            //console.log(page)
            this.currentPage = page
        },
        tableSizeChange(val) {
            //console.log(val)
            this.tablesize = val
            this.tablekpi()
        },
        tableCurrentImportDeptChange(page) {
            //console.log(page)
            this.tablecurrent = page
            this.tablekpi()
        },
        handleSizeChange2(val) {
            //console.log(val)
            this.pageSize2 = val
        },
        handleCurrentImportDeptChange2(page) {
            //console.log(page)
            this.currentPage2 = page
        },
        handleSizeChange3(val) {
            //console.log(val)
            this.pageSize3 = val
        },
        handleCurrentImportDeptChange3(page) {
            //console.log(page)
            this.currentPage3 = page
        },
        handleSizeChange4(val) {
            //console.log(val)
            this.pageSize4 = val
        },
        handleCurrentImportDeptChange4(page) {
            //console.log(page)
            this.currentPage4 = page
        },
        problemSizeChange(val) {
            this.problemSize = val
        },
        problemCurrentImportDeptChange(val) {
            this.problemCurrent = val
        },
        problemSizeChangeProj(val) {
            this.problemSizeProj = val
        },
        problemCurrentImportDeptChangeProj(val) {
            this.problemCurrentProj = val
        },
        gerritSizeChange(val) {
            this.gerritSize = val
        },
        gerritCurrentImportDeptChange(val) {
            this.gerritCurrent = val
        },
        gerritSizeChangeProj(val) {
            this.gerritSizeProj = val
        },
        gerritCurrentImportDeptChangeProj(val) {
            this.gerritCurrentProj = val
        },
        defectSizeChange(val) {
            this.defectSize = val
        },
        defectCurrentImportDeptChange(val) {
            this.defectCurrent = val
        },
        defectSizeChangeProj(val) {
            this.defectSizeProj = val
        },
        defectCurrentImportDeptChangeProj(val) {
            this.defectCurrentProj = val
        },
        getProjProblem() {
            this.ploadingProj = true
            this.$axios.get(`${process.env.VUE_APP_KANBAN_HOST}/api/qa/proj-submitter-comments-rank?time=${this.filters.time}&projectId=${this.filters.projectId}`, {headers: getHeader()}).then(res => {
                if(res.status == 200) {
                    if(res.data.code == 200) {
                        this.ploadingProj = false
                        this.problemDataProj = res.data.comments_rank
                        this.problemTotalProj = this.problemDataProj.length
                    } else {
                        this.ploadingProj = false
                    }
                }
            })
        },
        getProjdefect() {
            this.defectLoadingProj = true
            this.$axios.get(`${process.env.VUE_APP_KANBAN_HOST}/api/qa/proj-owner-density-rank?time=${this.filters.time}&projectId=${this.filters.projectId}`, {headers: getHeader()}).then(res => {
                if(res.status == 200) {
                    if(res.data.code == 200) {
                        this.defectLoadingProj = false
                        this.defectDensityProj = res.data.density_rank
                        this.defectTotalProj = this.defectDensityProj.length
                    } else {
                        this.defectLoadingProj = false
                    }
                }
            })
        },
        getProjGerritTable() {
            this.gerritLoadingProj = true
            this.$axios.get(`${process.env.VUE_APP_KANBAN_HOST}/api/qa/proj-module-defect-info?time=${this.filters.time}&projectId=${this.filters.projectId}`, {headers: getHeader()}).then(res => {
                if(res.status == 200) {
                    if(res.data.code == 200) {
                        this.gerritLoadingProj = false
                        this.gerritTableProj = res.data.module_data
                        this.gerritTotalProj = this.gerritTableProj.length
                    } else {
                        this.gerritLoadingProj = false
                    }
                }
            })
        },
        getDeptGerritTable() {
            this.gerritLoading = true
            let data = {}
            if(this.filters.departList.length) {
                data = {departmentIds: this.filters.departmentId}
            } else {
                data = {departmentIds: this.allDepartmentList.allDepartmentList}
            }
            this.$axios.post(`${process.env.VUE_APP_KANBAN_HOST}/api/qa/dept-module-defect-info?time=${this.filters.time}`, data, {headers: getHeader()}).then(res => {
                if(res.status == 200) {
                    if(res.data.code == 200) {
                        this.gerritLoading = false
                        this.gerritTable = res.data.module_data
                        this.gerritTotal = this.gerritTable.length
                    } else {
                        this.gerritLoading = false
                    }
                }
            })
        },
        getDeptProblem() {
            this.ploading = true
            let data = {}
            if(this.filters.departList.length) {
                data = {departmentIds: this.filters.departmentId}
            } else {
                data = {departmentIds: this.allDepartmentList.allDepartmentList}
            }
            this.$axios.post(`${process.env.VUE_APP_KANBAN_HOST}/api/qa/dept-submitter-comments-rank?time=${this.filters.time}`, data, {headers: getHeader()}).then(res => {
                if(res.status == 200) {
                    if(res.data.code == 200) {
                        this.ploading = false
                        this.problemData = res.data.comments_rank
                        this.problemTotal = this.problemData.length
                    }
                }
            })

        },
        tablekpi() {
            this.loading = true
            let data = {}
            if(this.filters.departList.length) {
                data = {departmentIds: this.filters.departmentId}
            } else {
                data = {departmentIds: this.allDepartmentList.allDepartmentList}
            }
            this.$axios.post(`${process.env.VUE_APP_KANBAN_HOST}/api/qa/dept-proj-code-review-kpi?time=${this.filters.time}&page=${this.tablecurrent}`, data, {headers: getHeader()})
                .then((res) => {
                    if(res.status == 200) {
                        if(res.data.code == 200) {
                            this.loading = false
                            //console.log(res.data)
                            this.tableData = res.data.project_kpi_list
                            this.tabletotal = res.data.count
                        }
                    }
                })
        },
        getdaily() {
            this.loadingLine = true
            let data = {}
            if(this.filters.departList.length) {
                data = {departmentIds: this.filters.departmentId}
            } else {
                data = {departmentIds: this.allDepartmentList.allDepartmentList}
            }
            this.$axios.post(`${process.env.VUE_APP_KANBAN_HOST}/api/qa/dept-code-daily?time=${this.filters.time}&mode=chart`, data, {headers: getHeader()})
                .then((res) => {
                    if(res.status == 200) {
                        if(res.data.code == 200) {
                            this.loadingLine = false
                            //console.log(res.data)
                            this.patchData.rows = res.data.daily_list
                            this.patchData2.rows = res.data.daily_list
                            this.patchData3.rows = res.data.daily_list
                            res.data.daily_list.length !=0 ? this.dataEmpty = false : this.dataEmpty = true
                        }
                    }
                })
        },
        getdeptrank() {
            this.loading2 = true
            let data = {}
            if(this.filters.departList.length) {
                data = {departmentIds: this.filters.departmentId}
            } else {
                data = {departmentIds: this.allDepartmentList.allDepartmentList}
            }
            // this.$axios.post(`${process.env.VUE_APP_KANBAN_HOST}/api/qa/proj-personal-rank-by-code-kpi?time=${this.filters.time}`, data)
            //     .then((res) => {
            //         if(res.status == 200) {
            //             if(res.data.code == 200) {
            //                 //console.log(res.data)
            //                 this.deptrank1 = res.data.rank_list
            //                       this.totalDeptData = res.data.rank_list.length
            //             }
            //         }
            //     })

            this.$axios.post(`${process.env.VUE_APP_KANBAN_HOST}/api/qa/dept-projrank-by-inline-comments?time=${this.filters.time}&mode=chart`, data, {headers: getHeader()})
                .then((res) => {
                    if(res.status == 200) {
                        if(res.data.code == 200) {
                            this.loading2 = false
                            //console.log(res.data)
                            this.deptrank2 = res.data.rank_list
                            if(res.data.rank_list) {
                                this.totalDeptData2 = res.data.rank_list.length
                            }
                        }
                    }
                })
        },
        getDeptRank2() {
            this.loading3 = true
            let data = {}
            if(this.filters.departList.length) {
                data = {departmentIds: this.filters.departmentId}
            } else {
                data = {departmentIds: this.allDepartmentList.allDepartmentList}
            }
            this.$axios.post(`${process.env.VUE_APP_KANBAN_HOST}/api/qa/dept-projrank-by-defect-density?time=${this.filters.time}&mode=chart`, data, {headers: getHeader()})
                .then((res) => {
                    if(res.status == 200) {
                        if(res.data.code == 200) {
                            this.loading3 = false
                            //console.log(res.data)
                            this.deptrank3 = res.data.rank_list
                            if(res.data.rank_list) {
                                this.totalDeptData3 = res.data.rank_list.length
                            }
                        }
                    }
                })

            this.$axios.post(`${process.env.VUE_APP_KANBAN_HOST}/api/qa/dept-projrank-by-effective-ratio?time=${this.filters.time}&mode=chart`, data, {headers: getHeader()})
                .then((res) => {
                    if(res.status == 200) {
                        if(res.data.code == 200) {
                            //console.log(res.data)
                            this.deptrank4 = res.data.rank_list
                            if(res.data.rank_list) {
                                this.totalDeptData4 = res.data.rank_list.length
                            }
                        }
                    }
                })
        },
        getdeptCodeSummary() {
            let data = {}
            this.deptlable = {}
            if(this.filters.departList.length) {
                data = {departmentIds: this.filters.departmentId}
            } else {
                data = {departmentIds: this.allDepartmentList.allDepartmentList}
            }
            this.$axios.post(`${process.env.VUE_APP_KANBAN_HOST}/api/qa/dept-code-summary?time=${this.filters.time}`, data, {headers: getHeader()})
                .then((res) => {
                    if(res.status == 200) {
                        if(res.data.code == 200) {
                            //console.log(res.data)
                            this.deptlable = res.data.summary
                        }
                    }
                })
        },
        showData(data) {
            if (null == data || "undefined" == typeof(data) || "" == data) {
                return 0;
            } else {
                return data
            }
        },
        getCodeSummary: function(project, time, departmentId) {
            this.label_data = {}
            // projcodesummary?projectId=3903
            let source = `/api/qa/projcodesummary?projectId=${project}&time=${time}`
            this.$axios.get(source, {headers: getHeader()})
                .then((response) => {
                    //console.log(response)
                    if (response.status == 200) {
                        if (response.data.code == 200) {
                            this.label_data = response.data.data;
                        }
                    }
                })
                .catch((err) => {
                    // eslint-disable-next-line
                    console.log(err);
                });
        },
        // handle eldatepickersingle event filter_object
        filterObject: function() {
            // this.filters = filterChange;
            // this.label_info.patch_without_inline_c.daterange = this.filters.date;
            this.getData()
        },
        getFix: function(data) {
            if (null == data || "undefined" == typeof(data) || "" == data) {
                return 0;
            } else {
                return data
            }
        },
        getNum(num) {
            let number
            if(num) {
                number = Number(num).toFixed(2)
            } else {
                number = 0
            }
            return number
        }
    },
    created: function() {
        // this.project_id = this.$route.params.pmsProjectId;
    },
    mounted: function() {
        // this.getAllBranch(this.project_id);
        this.getData();
    }
}
</script>
<style lang="scss" scoped>
    @import '../../assets/common/common.scss';
    #GerrirReview{
        padding: 32px;
        background-color: rgb(240, 242, 245);
        position: relative;
    }
    .border{
        box-sizing: content-box;
        height: 0;
        overflow: visible;
        margin-top: 1rem;
        margin-bottom: 1rem;
        border: 0;
        border-top: 1px solid rgba(0,0,0,.1);
    }
    .primary{
        color: #409EFF;
        font-size: 30px;
        margin-top: 20px;
        margin-bottom: 10px;
        font-weight: 400;
    }
    .bgColor{
        background: #fff;
    }
    .pad{
        padding: 0 20px;
        padding-top: 20px;
    }
    .marT{
        margin-top: 20px;
    }
    .mar{
        margin: 0 20px;
        margin-top: 20px;
    }
    .table{
        padding-bottom: 10px;
    }
    #GerrirReview >>> .el-card{
        border: 0;
    }
    #GerrirReview >>> .dangerous .el-radio-button__orig-radio:checked+.el-radio-button__inner{
        background-color: #ed5565;
        border-color: #ed5565;
        box-shadow: -1px 0 0 0 #ed5565;
    }
    #GerrirReview >>> .dangerous .el-radio-button__orig-radio:checked+.el-radio-button__inner:hover{
        color: #fff;
    }
    #GerrirReview >>> .el-radio-button__inner:hover {
        color: #ed5565;
    }
</style>

